Back to course home
0% completed
Vote For New Content
Google Hard
Shortest Subarray with Sum at Least K (hard)
Solution: Shortest Subarray with Sum at Least K
Reverse Pairs (hard)
Solution: Reverse Pairs
Nth Magical Number (hard)
Solution: Nth Magical Number
Candy (hard)
Solution: Candy
Arithmetic Slices II - Subsequence (hard)
Solution: Arithmetic Slices II - Subsequence
Burst Balloons (hard)
Solution: Burst Balloons
Sum of Distances in Tree (hard)
Solution: Sum of Distances in Tree
Maximum Score of a Good Subarray (hard)
Solution: Maximum Score of a Good Subarray
Trapping Rain Water (hard)
Solution: Trapping Rain Water
First Missing Positive (hard)
Solution: First Missing Positive
4Sum II (medium)
Problem Statement
Given four arrays of integers nums1, nums2, nums3, and nums4 of the same length n, return the count of tuples (i, j, k, l) such that:
0 <= i, j, k, l < nnums1[i] + nums2[j] + nums3[k] + nums4[l] == 0
Examples
Example 1:
- Input: nums1 = [1], nums2 = [-1], nums3 = [0], nums4 = [0]
- Expected Output: 1
- Justification: The one quadruplet that sum up to 0 is:
- (1, -1, 0, 0)
Example 2:
- Input: nums1 = [0, 1], nums2 = [1, -1], nums3 = [-1, 0], nums4 = [1, -1]
- Expected Output: 4
- Justification: The four quadruplets that sum up to 0 are:
- (0, 1, 0, -1)
- (0, -1, 0, 1)
- (1, -1, -1, 1)
- (1, 1, -1, -1)
Example 3:
- Input: nums1 = [-1, 3], nums2 = [2, -3], nums3 = [3, 4], nums4 = [-4, -3]
- Expected Output: 3
- Justification: The three quadruplets that sum up to 0 are:
- (-1, 2, 3, -4)
- (3, -3, 4, -4)
- (3, -3, 3, -3)
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Single Number II
Solution: 4Sum II
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself